/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javalens.datageneration;

import javalens.astronomy.Event;
import javalens.*;
import javalens.util.ShouldNeverHappenException;

/**
 *
 * @author Pierre
 */
public class FlatNoParallaxEventGenerator implements EventGenerator {

    private Event minimum;
    private Event maximum;

    public FlatNoParallaxEventGenerator() {
        this.minimum = new Event(1.0e-3, 5, -10, 16);
        this.minimum.setA(0.2);
        this.minimum.setAng(0);
        this.minimum.setF(0.5);
        this.minimum.setQ(1.0e-3);

        this.maximum = new Event(2.0, 30, 10, 22);
        this.maximum.setA(5.0);
        this.maximum.setAng(360);
        this.maximum.setF(1.0);
        this.maximum.setQ(1.0);
    }

    public FlatNoParallaxEventGenerator(Event minimum, Event maximum) throws ShouldNeverHappenException {
        if (minimum.getA() > maximum.getA() ||
                minimum.getAng() > maximum.getAng() ||
                minimum.getB() > maximum.getB() ||
                minimum.getF() > maximum.getF() ||
                minimum.getQ() > maximum.getQ() ||
                minimum.getPsi() > maximum.getPsi() ||
                minimum.getRho() > maximum.getRho() ||
                minimum.getRs() > maximum.getRs() ||
                minimum.getTe() > maximum.getTe() ||
                minimum.getTm() > maximum.getTm()) {
            throw new ShouldNeverHappenException("Min event param larger than max param in generator.");
        }
        this.minimum = minimum;
        this.maximum = maximum;
    }

    public Event next() {
        double a, ang, b, q, m0, te, tm, f;
        a = Math.random() * (maximum.getA() - minimum.getA()) + minimum.getA();
        ang = Math.random() * (maximum.getAng() - minimum.getAng()) + minimum.getAng();
        b = Math.random() * (maximum.getB() - minimum.getB()) + minimum.getB();
        q = Math.random() * (maximum.getQ() - minimum.getQ()) + minimum.getQ();
        te = Math.random() * (maximum.getTe() - minimum.getTe()) + minimum.getTe();
        tm = Math.random() * (maximum.getTm() - minimum.getTm()) + minimum.getTm();
        m0 = Math.random() * (maximum.getM0() - minimum.getM0()) + minimum.getM0();
        f = Math.random() * (maximum.getF() - minimum.getF()) + minimum.getF();
        Event ret = new Event(b, te, tm, m0);
        ret.setA(a);
        ret.setAng(ang);
        ret.setQ(q);
        ret.setF(f);
        return ret;
    }
}
